package Lib3d.EventListeners;


import Lib3d.Animation.SimpleAnimationImpl;
import Lib3d.MyUtils.Camera;
import Lib3d.MyUtils.Debug;
import Lib3d.PresetModel3d.Sphere;
import main.JavaMain;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * A key listener implementation used by the main application's canvas.
 * 
 * @author Wassim Chegham
 * @version 0.1
 * @category Lib3d.EventListener
 * 
 */
public class MyKeyListener implements KeyListener {

    public void keyPressed(final KeyEvent e) {

        switch (e.getKeyCode()) {
            case KeyEvent.VK_ESCAPE:
                JavaMain.bQuit = true;
                JavaMain.displayT.interrupt();
                System.exit(0);
                break;
            case KeyEvent.VK_UP:
            case KeyEvent.VK_Z:
                Camera.moveForward(10f);
                break;
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_S:
                Camera.moveBackward(10f);
                break;
            case KeyEvent.VK_LEFT:
            case KeyEvent.VK_Q:
                if (e.isShiftDown()) {
                    Camera.turnLeft(2f);
                }
                else {
                    Camera.moveLeft(10f);
                }
                break;
            case KeyEvent.VK_RIGHT:
            case KeyEvent.VK_D:
                if (e.isShiftDown()) {
                    Camera.turnRight(2f);
                }
                else {
                    Camera.moveRight(10f);
                }
                break;
            case KeyEvent.VK_A:
                SimpleAnimationImpl.toggle();
                break;
            case KeyEvent.VK_C:
                SimpleAnimationImpl.changeSense();
                break;
            case KeyEvent.VK_B:
                Debug.showGlobalBBox = !Debug.showGlobalBBox;
                break;
            case KeyEvent.VK_N:
                Debug.showSingleBBox = !Debug.showSingleBBox;
                break;
            case KeyEvent.VK_P:
                Debug.showHairs = !Debug.showHairs;
                break;
            case KeyEvent.VK_H:
                Debug.showHelp = !Debug.showHelp;
                break;
            case KeyEvent.VK_L:
                Debug.gluDrawStyle = Sphere.GLU_LINE;
                break;
            case KeyEvent.VK_F:
                Debug.gluDrawStyle = Sphere.GLU_FILL;
                break;
            case KeyEvent.VK_M:
                Debug.showMasses = !Debug.showMasses;
                break;
            case KeyEvent.VK_X:
                Debug.showAxis = !Debug.showAxis;
                break;
            case KeyEvent.VK_1:
                Camera.viewAxixX();
                break;
            case KeyEvent.VK_2:
                Camera.viewAxixY();
                break;
            case KeyEvent.VK_3:
                Camera.viewAxixZ();
                break;
            case KeyEvent.VK_PAGE_UP:
                Debug.ANIMATION_SPEED_UP = true;
                break;
            case KeyEvent.VK_PAGE_DOWN:
                Debug.ANIMATION_SPEED_DOWN = true;
                break;
        }

    }

    public void keyReleased(final KeyEvent e) {

        switch (e.getKeyCode()) {
            case KeyEvent.VK_PAGE_UP:
                Debug.ANIMATION_SPEED_UP = false;
                break;
            case KeyEvent.VK_PAGE_DOWN:
                Debug.ANIMATION_SPEED_DOWN = false;
                break;
        }

    }

    public void keyTyped(final KeyEvent e) {}

}
